package com.andy.blog.quartz.service.impl;

import com.andy.blog.common.page.PageUtilsDTO;
import com.andy.blog.common.utils.TransformUtils;
import com.andy.blog.dal.domain.SysJobLogDO;
import com.andy.blog.dal.service.SysJobLogDalService;
import com.andy.blog.dal.vo.SysJobLogVO;
import com.andy.blog.quartz.dto.SysJobLogDTO;
import com.andy.blog.quartz.service.SysJobLogBusService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 定时任务调度日志信息 服务层
 * Created by andy on 2023-04-05 11:38
 */
@Service
public class SysJobLogBusServiceImpl implements SysJobLogBusService {

    @Resource
    private SysJobLogDalService sysJobLogDalService;

    /**
     * 获取quartz调度器日志的计划任务
     *
     * @param sysJobLogVO 调度日志信息
     * @return 调度任务日志集合
     */
    @Override
    public PageUtilsDTO<SysJobLogDTO> selectListByPage(SysJobLogVO sysJobLogVO) {
        IPage<SysJobLogDO> doiPage = sysJobLogDalService.selectListByPage(sysJobLogVO);
        return PageUtilsDTO.build(doiPage.getTotal(), TransformUtils.transformList(doiPage.getRecords(), SysJobLogDTO.class));
    }

    @Override
    public List<SysJobLogDTO> selectListByCondition(SysJobLogVO sysJobLogVO) {
        List<SysJobLogDO> sysJobLogDOS = sysJobLogDalService.selectListByCondition(sysJobLogVO);
        return TransformUtils.transformList(sysJobLogDOS, SysJobLogDTO.class);
    }

    /**
     * 通过调度任务日志ID查询调度信息
     *
     * @param jobLogId 调度任务日志ID
     * @return 调度任务日志对象信息
     */
    @Override
    public SysJobLogDTO selectJobLogById(Long jobLogId) {
        SysJobLogDO sysJobLogDO = sysJobLogDalService.selectById(jobLogId);
        return TransformUtils.transform(sysJobLogDO, SysJobLogDTO.class);
    }

    /**
     * 新增任务日志
     *
     * @param sysJobLogVO 调度日志信息
     */
    @Override
    public void addJobLog(SysJobLogVO sysJobLogVO) {
        sysJobLogDalService.insertJobLog(sysJobLogVO);
    }

    /**
     * 批量删除调度日志信息
     *
     * @param logIds 需要删除的数据ID
     * @return 结果
     */
    @Override
    public void deleteJobLogByIds(List<Long> logIds) {
        sysJobLogDalService.deleteByIds(logIds);
    }

    /**
     * 删除任务日志
     *
     * @param jobId 调度日志ID
     */
    @Override
    public int deleteById(Long jobId) {
        return sysJobLogDalService.deleteById(jobId);
    }

    /**
     * 清空任务日志
     */
    @Override
    public void cleanJobLog() {
        sysJobLogDalService.cleanJobLog();
    }
}
